"""
ASGI config for quant_back project.

It exposes the ASGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""

import os
import django

# 设置Django环境
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'quant_back.settings')
django.setup()

# 在Django设置完成后导入其他模块
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.auth import AuthMiddlewareStack
import tushare_data.routing as routings
import data_analysis.routing as data_analysis_routing

# 获取ASGI应用
django_asgi_app = get_asgi_application()

from channels.security.websocket import AllowedHostsOriginValidator

application = ProtocolTypeRouter({
    "http": django_asgi_app,
    "websocket": AllowedHostsOriginValidator(
        AuthMiddlewareStack(
            URLRouter(
                routings.websocket_urlpatterns + data_analysis_routing.websocket_urlpatterns
            )
        )
    ),
})